package com.sh.sales.happysales.webconfig;

import android.content.Context;
import android.webkit.JavascriptInterface;

import com.sh.sales.happysales.app.AppData;
import com.sh.sales.happysales.app.utils.LoginOutUtil;
import com.sh.sales.happysales.app.utils.LoginUtil;
import com.sh.sales.happysales.base.BaseMessageEvent;
import com.sh.sales.happysales.view.NewToast;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by zhouyucheng on 2017/9/18.
 */

public class KnowledgeJs implements ActivityFunc {
    private Context mContext;

    public KnowledgeJs(Context mContext) {
        this.mContext = mContext;

    }

    @JavascriptInterface
    @Override
    public void saveSign(String accessToken) {
        System.out.println("H5端accessToken刷新==》：" + accessToken);
        AppData.getInstence().getmUserToken().setAccessToken(accessToken);
        LoginUtil.getInstance().catchUserInfo(AppData.getInstence().getmUserToken(), mContext, 2);
    }

    @JavascriptInterface
    @Override
    public String getSign() {
        return AppData.getInstence().getmUserToken().getUserSign();
    }

    @JavascriptInterface
    @Override
    public void errorCode() {
        LoginOutUtil.logOut(mContext);
    }

    @JavascriptInterface
    @Override
    public void gotoRank() { //界面切换进排行榜
        EventBus.getDefault().post(new BaseMessageEvent(EventType.GoToRank));
    }

    @JavascriptInterface
    @Override
    public void goback() { //退回收益
        EventBus.getDefault().post(new BaseMessageEvent(EventType.GoBack));
    }

    @JavascriptInterface
    @Override
    public void htmlToast(String message) {
        NewToast.makeText(mContext,message);
    }
}
